package org.apache.lorry.demo.consumer;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords;

import java.util.Arrays;
import java.util.Iterator;

@Slf4j
public class TopicConsumerDemo2 {
    public static void main(String[] args) {
        TopicConsumer topicConsumer = new TopicConsumer("localhost:9092", "test_group_1");
        topicConsumer.startConsumer(Arrays.asList("test_topic_1"));
        while(true) {
            ConsumerRecords consumerRecords = topicConsumer.pool(1000);
            Iterator<ConsumerRecord> iterator = consumerRecords.iterator();
            while(iterator.hasNext()) {
                ConsumerRecord consumerRecord = iterator.next();
                log.info("consumerRecord: {}", JSON.toJSONString(consumerRecord));
            }
        }
    }
}
